

package cn.shengchao.controler.course;

import cn.shengchao.util.helper.LoginHelper;
import cn.shengchao.examstar.me.play.ohs.local.appservices.CoursePlayLogAppService;
import cn.shengchao.examstar.me.play.ohs.local.messages.CoursePlayLogDto;
import cn.shengchao.examstar.me.play.ohs.local.messages.StudyWeekly;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.continew.starter.log.annotation.Log;

@RestController
@Slf4j
@CrossOrigin("${project.cross-origin}")
@RequestMapping("/api/${project.version}/coursePlayLog")
public class CoursePlayLogController {

    @Autowired
    private CoursePlayLogAppService coursePlayLogAppService;

    @Log(ignore = true)
    @PostMapping
    public void saveCoursePlayLog(@RequestBody CoursePlayLogDto coursePlayLogDto) {
        Long userId = LoginHelper.getUserId();
        coursePlayLogAppService.saveCoursePlayLog(coursePlayLogDto, userId);
    }

    @GetMapping("studyWeekly")
    @Operation(description = "本周学习时长")
    public StudyWeekly studyWeekly() {
        return coursePlayLogAppService.studyWeekly(LoginHelper.getUserId());
    }

}
